package nl.vu.few.ibivu.biomodels.client.ui;

import nl.vu.few.ibivu.biomodels.client.activity.MainActivityMapper;
import nl.vu.few.ibivu.biomodels.client.activity.MenuActivityMapper;
import nl.vu.few.ibivu.biomodels.client.presenter.GatewayPresenter;
import nl.vu.few.ibivu.biomodels.client.presenter.MessagePresenter;
import nl.vu.few.ibivu.biomodels.client.ui.base.ContentCanvas;

import com.google.gwt.activity.shared.ActivityManager;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.place.shared.PlaceController;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import com.smartgwt.client.types.Alignment;
import com.smartgwt.client.types.ImageStyle;
import com.smartgwt.client.widgets.Img;
import com.smartgwt.client.widgets.Label;
import com.smartgwt.client.widgets.layout.HLayout;
import com.smartgwt.client.widgets.layout.LayoutSpacer;
import com.smartgwt.client.widgets.layout.VLayout;

@Singleton
public class MainView extends HLayout {
	
	@Inject
	public MainView(
			EventBus eventBus,
			PlaceController placeController,
			MainActivityMapper mainActivityMapper,
			MenuActivityMapper menuActivityMapper,
			GatewayPresenter gatewayPresenter,
			MessagePresenter messagePresenter) {
		
		this.setWidth100();
		this.setHeight100();
		
		// Create central view content layout
		VLayout mainViewContent = new VLayout();
		mainViewContent.setWidth100();
		mainViewContent.setHeight100();
		mainViewContent.setAlign(Alignment.CENTER);
		
		// Create header
		HLayout headerLayout = new HLayout();
		Img logo = new Img("/images/logo.png");
		logo.setImageType(ImageStyle.NORMAL);
		logo.setWidth(240);
		logo.setHeight(70);
		/*
		logo.setAutoHeight();
		logo.setAutoWidth();
		*/
		headerLayout.addMember(logo);
		LayoutSpacer headerSpacer = new LayoutSpacer();
		headerSpacer.setWidth("*");
		headerLayout.addMember(headerSpacer);
		headerLayout.addMember(gatewayPresenter.getView());
		headerLayout.setAutoHeight();
		mainViewContent.addMember(headerLayout);
		
		// Create the MenuCanvas
		ContentCanvas menuCanvas = new ContentCanvas();
		menuCanvas.setAutoHeight();
		mainViewContent.addMember(menuCanvas);
		
		// Create the CenterCanvas
		ContentCanvas centerCanvas = new ContentCanvas();
		mainViewContent.addMember(centerCanvas);
		
		// Create the Footer
		Label footerLabel = new Label();
		footerLabel.setContents("&#169;2011 Nicola Bonzanni - Centre for Integrative Bioinformatics VU");
		footerLabel.setAutoHeight();
		footerLabel.setAlign(Alignment.CENTER);
		mainViewContent.addMember(footerLabel);
		
		LayoutSpacer leftSpacer = new LayoutSpacer();
		leftSpacer.setWidth("5%");
		LayoutSpacer rightSpacer = new LayoutSpacer();
		rightSpacer.setWidth("5%");
		this.addMember(leftSpacer);
		this.addMember(mainViewContent);
		this.addMember(rightSpacer);
		
		/*
		 * Wire up the ActivityManagerS
		 */
		
		ActivityManager mainActivityManager = new ActivityManager(mainActivityMapper, eventBus);
		mainActivityManager.setDisplay(centerCanvas);


		ActivityManager menuActivityManager = new ActivityManager(menuActivityMapper, eventBus);
		menuActivityManager.setDisplay(menuCanvas);
	}
}
